varying vec3 pEyeVec;			//	vertex_to_eye vector (in TBN space)
varying vec3 pLightDir;			//	light_to_vertex vector  (in TBN space)
varying vec2 pTexCoord;			//	texture coordinate

uniform sampler2D colorMap;
uniform sampler2D normalMap;
	
uniform vec3 ambientParameter;
uniform vec3 diffuseParameter;	
uniform vec3 specularParameter;	
uniform float shinessParameter;

void main() 
{
	vec3 base = texture2D(colorMap, pTexCoord).xyz;	
	vec3 final_color = ambientParameter * base;
	vec3 N = normalize(texture2D(normalMap, pTexCoord).xyz * 2.0 - 1.0);
	vec3 L = normalize(pLightDir);
	
	float dotTerm = dot(N, -L);
	if (dotTerm > 0.0)
    {
		final_color += base * diffuseParameter * dotTerm;
		vec3 E = normalize(pEyeVec);
		vec3 R = reflect(L, N);		//	reflect light
		float dotTerm2 = dot(R, E);
		if (dotTerm2 > 0.0)
			final_color += base * specularParameter * pow(dotTerm2, shinessParameter);	
    }

	gl_FragColor = vec4(final_color, 1.0);
} 